<template>
    <div class="brand">
       <div class="brand-head">
        <div class="search">
            <el-form class="search-form" >
                <el-row>
                <el-col :span="5">
                    <el-form-item label="型号：" label-width="100px">
                        <el-input v-model="form.partNumber"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="5">
                    <el-form-item label="品牌：" label-width="100px">
                        <el-input v-model="form.brand"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="5">
                    <el-form-item label="创建人：" label-width="100px">
                        <el-input v-model="form.createUser"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="5">
                    <el-form-item label="审核状态："  label-width="100px">
                        <el-select v-model="form.auditStatus" placeholder="请选择审核状态" style="width:100%">
                            <el-option
                                v-for="item in examineOption"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value">
                            </el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
                <el-col class="btn-box" :span="4">
                    <el-button type="primary" class="btn" @click="doRefresh()">查 询</el-button>
                    <el-button  class="btn" @click="doReset()">重 置</el-button>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="5">
                    <el-form-item label="优势状态："  label-width="100px">
                        <el-select v-model="form.advantageStatus" placeholder="请选择优势状态" style="width:100%">
                            <el-option
                                v-for="item in advantageOption"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value">
                            </el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
            </el-row>
            </el-form>
        </div>
       </div>
       <div class="operation-box">
            <el-button type="primary" @click="getAdd">单条新增</el-button>
            <el-button type="primary" @click="getDelay">批量新增</el-button>
            <el-button type="primary" @click="getConcel" :disabled="isbtndisabled">取消</el-button>
            <el-button type="primary" @click="getApply"  :disabled="isbtndisabled">再次发起</el-button>
            <el-button type="danger" @click="getDel" :disabled="isbtndisabled">删除</el-button>
       </div>
       <div class="table-box">
        <!-- 表格 -->
            <myTable ref="mytable"
                :config="tableconfig"
                @handleSelectChange="handleSelectChange" 
                @checkedAll="checkedAllVal"
                :checkedStatus="allParams.isAll"
                >
                <div slot="mytablebody">
                </div>
                 <!-- 审核状态 -->
                 <template v-slot:auditStatus="{ data }">
                    <el-link type="warning" v-if="data.auditStatus==0" :underline="false"> 待审核 </el-link>
                    <el-link type="success" v-if="data.auditStatus==1" :underline="false"> 审核通过</el-link>
                    <div  v-if="data.auditStatus==2">
                        <el-tooltip  class="item" effect="dark"  placement="top"  :disabled="data.refusedReason == null">
                            <div slot="content">{{ data.refusedReason }}</div>
                            <el-link type="danger" :underline="false">审核拒绝 </el-link>
                        </el-tooltip>
                    </div>
                </template>
                <!-- 优势状态 -->
                <template v-slot:advantageStatus="{ data }">
                    <p v-if="data.advantageStatus == 0">无效</p>
                    <p v-if="data.advantageStatus == 1">正常</p>
                </template>
                <!-- 有效期 validityDateStart-->
                <template v-slot:validityDateStart="{ data }">
                    <p v-if="data.validityDateStart">{{ data.validityDateStart }}</p>
                    <p v-else>-</p>
                </template>
                <template v-slot:validityDateEnd="{ data }">
                    <p v-if="data.validityDateEnd">{{ data.validityDateEnd }}</p>
                    <p v-else>-</p>
                </template>

            </myTable> 
        </div>
        <!-- 新增 -->
        <el-dialog title="单条新增" :visible.sync="dialogAddVisible" width="40%" @close="closeAdd" class="add-dialog">
            <el-form :model="add_form" class="addform" :rules="rules" ref="addform">
                <el-form-item label="优势型号：" :label-width="formLabelWidth" prop="partNumber" >
                    <el-input v-model="add_form.partNumber" autocomplete="off" @blur="onInputBlur($event)" @change="onInputChange"></el-input>
                    <div class="el-form-item__error " v-show="isShow">请在库存中添加该型号后申请</div>
                </el-form-item>
                <el-form-item label="品牌：" :label-width="formLabelWidth" prop="brand">
                    <el-select v-model="add_form.brand" placeholder="请选择品牌" style="width:100%" :disabled="isDisabled">
                        <el-option :label="item" :value="item" v-for="item in brandList" :key="item"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="有效期：" :label-width="formLabelWidth" prop="createDate">
                    <el-date-picker v-model="add_form.createDate"
                        style="width:100%"
                        type="daterange"
                        unlink-panels
                        range-separator="至"
                        start-placeholder="开始日期"
                        end-placeholder="结束日期"
                        value-format="yyyy-MM-dd"
                        :picker-options="pickerOptions">
                    </el-date-picker>
                </el-form-item>
                <el-form-item label="备注：" :label-width="formLabelWidth" prop="remark">
                    <el-input type="textarea" v-model="add_form.remark"   maxlength="100"  show-word-limit></el-input>
                </el-form-item>
                
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="getaddSubmit('addform')" v-preventReClick>确 认</el-button>
                <el-button @click="dialogAddVisible = false">取 消</el-button>
            </div>
        </el-dialog>
        <!-- 取消 -->
        <el-dialog title="取消" :visible.sync="dialogCancelVisible" width="20%" class="cancel-dialog">
            <div class="del-box">
              <img src="@/assets/images/concel.png" alt="" class="concel-icon"/>
                <p class="del-content">您确认取消该优势型号吗？</p>
            </div>
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="getaCancelSubmit()">确 认</el-button>
                <el-button @click="dialogCancelVisible = false">取 消</el-button>
               
            </div>
        </el-dialog>
        <!-- 批量新增 -->
        <el-dialog title="批量新增" :visible.sync="dialogDelayVisible" width="40%" @close="closeBatchAdd" class="add-dialog">
            <el-form :model="batch_form" class="addform" :rules="batchrules" ref="batch_form">
                <el-form-item class="upload-box" :label-width="formLabelWidth">
                    <uploadXlsx @batchData="batchData" @clear="clearUpload" :modelList="modelList"></uploadXlsx>
                </el-form-item>
                <el-form-item label="有效期：" :label-width="formLabelWidth" prop="createDate">
                    <el-date-picker v-model="batch_form.createDate"
                        style="width:100%"
                        type="daterange"
                        unlink-panels
                        range-separator="至"
                        start-placeholder="开始日期"
                        end-placeholder="结束日期"
                        value-format="yyyy-MM-dd"
                        :picker-options="pickerOptions">
                        </el-date-picker>
                    </el-form-item>
                </el-form>
           
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="getbatchSubmit('batch_form')" v-preventReClick>确 认</el-button>
                <el-button @click="dialogDelayVisible = false">取 消</el-button>
            </div>
        </el-dialog>
        <!-- 导出结果 -->
        <el-dialog title="导入失败" :visible.sync="dialogresultVisible" >
            <div class="result-box">
                <div class="approved-box" v-if="gridData.approvedDataCount > 0">
                    <p class="result-num">此次导入包含<span>{{gridData.approvedDataCount}}</span>条已"审核通过"状态数据</p>
                    <el-table :data="gridData.approvedData" :height="350" border>
                        <el-table-column property="tableName" label="表格名称" ></el-table-column>
                        <el-table-column property="partNumber" label="型号">
                        </el-table-column>
                        <el-table-column property="brand" label="品牌">
                        </el-table-column>
                    </el-table>
                    <p class="tips">当前优势型号在有效期内，无需重复申请</p>
                </div>
                <div class="approved-box" v-if="gridData.reviewedDataCount > 0">
                    <p class="result-num">此次导入包含<span>{{gridData.reviewedDataCount}}</span>条“待审核”状态数据</p>
                    <el-table :data="gridData.reviewedData" :height="350" border>
                        <el-table-column property="tableName" label="表格名称" ></el-table-column>
                        <el-table-column property="partNumber" label="型号">
                        </el-table-column>
                        <el-table-column property="brand" label="品牌">
                        </el-table-column>
                    </el-table>
                    <p class="tips">请等待耐心审核结果</p>
                </div>
                <div class="approved-box" v-if="gridData.inventoryNoHaveDataCount > 0">
                    <p class="result-num">此次导入包含<span>{{gridData.inventoryNoHaveDataCount}}</span>条“库存数据不存在”数据</p>
                    <el-table :data="gridData.inventoryNoHaveData" :height="350" border>
                        <el-table-column property="tableName" label="表格名称" ></el-table-column>
                        <el-table-column property="partNumber" label="型号">
                        </el-table-column>
                        <el-table-column property="brand" label="品牌">
                        </el-table-column>
                    </el-table>
                    <p class="tips">请添加对应型号库存后，再次进行申请</p>
                </div>
            </div>
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="gettableSumbit">确 认</el-button>
            </div>
        </el-dialog>
        <!-- 再次发起 -->
        <el-dialog title="再次发起" :visible.sync="dialogApplyVisible" width="28%" class="apply-dialog" @close="closeApply">
            <div class="applyform">
                <el-form :model="applyform"  :rules="applyRules" ref="applyform">
                    <el-form-item label="有效期：" :label-width="formLabelWidth" prop="createDate">
                        <el-date-picker v-model="applyform.createDate"
                            style="width:100%"
                            type="daterange"
                            unlink-panels
                            range-separator="至"
                            start-placeholder="开始日期"
                            end-placeholder="结束日期"
                            value-format="yyyy-MM-dd"
                            :picker-options="pickerOptions">
                            </el-date-picker>
                    </el-form-item>
                    <el-form-item label="备注：" :label-width="formLabelWidth" prop="remark">
                        <el-input
                            type="textarea"
                            v-model="applyform.remark"
                            maxlength="100"
                            show-word-limit
                            >
                        </el-input>
                    </el-form-item>
                </el-form>
            </div>
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="getApplySubmit('applyform')">确 认</el-button>
                <el-button @click="dialogApplyVisible = false">取 消</el-button>
            </div>
        </el-dialog>
        <!-- 删除 -->
        <el-dialog title="删除" :visible.sync="dialogDelVisible" width="20%" class="cancel-dialog">
            <div class="del-box">
                <i class="el-icon-delete del-icon"></i>
                <p class="del-content">您确认删除该优势型号吗？</p>
            </div>
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="getDelSubmit()">确 认</el-button>
                <el-button @click="dialogDelVisible = false">取 消</el-button>
            </div>
        </el-dialog>
    </div>
</template>

<script>
    import { modelList,addModel,queryBrandsByPartNumber,checkAdvantageModel,cancleAdvantageModel,againInitiate,deleteModel,batchAdd} from "@/api/stock"
    import uploadXlsx from './uploadXlse.vue'
    export default {
        name:'advantageBrand',
        components:{uploadXlsx},
        data(){
            return{
                form:{
                    partNumber:"",
                    brand:'',
                    createUser:'',
                    auditStatus:'',
                    advantageStatus:'',
                    pageNo:1,
                    pageSize:10,
                },
                examineOption:[
                    {
                        value: '0',
                        label: '待审核'
                    },
                    {
                        value: '1',
                        label: '审核通过'
                    },
                    {
                        value: '2',
                        label: '审核拒绝'
                    }

                ],
                advantageOption:[
                    {
                        value:"1",
                        label:'正常'
                    },
                    {
                        value:"0",
                        label:'无效'
                    }
                ],
                tableconfig: {
                    loading: false,
                    isselection: true,
                    ispagination: true,
                    tabledata: [],
                    isindex: true,
                    thead: [
                    { sort: null, label: '型号', prop: 'partNumber', width: 250 },
                    { sort: null, label: '品牌', prop: 'brand', width: 250 },
                    { sort: null, label: '创建人', prop: 'createUser', width: 200 },
                    { sort: null, label: '审核状态', prop: 'auditStatus', width: 150,type: 'slot'},
                    { sort: null, label: '优势状态', prop: 'advantageStatus', width: 150,type: 'slot'},
                    { sort: null, label: '有效期开始', prop: 'validityDateStart', width: 150,type: 'slot'},
                    { sort: null, label: '有效期截止', prop: 'validityDateEnd', width: 150,type: 'slot'},
                    { sort: null, label: '备注', prop: 'remark' },     
                    ],
                    // checkedAll: false, //全选所有
                    checkedPage: false, //全选本页
                    currentpage: 1,
                    pagesize: 1,
                    total: 3,
                },
                // 当前选中的行数据
                selectrow: [],
                isbtndisabled:true,
                dialogAddVisible:false, //新增弹框
                dialogDelVisible:false,//删除弹框
                dialogCancelVisible:false,//取消弹框
                dialogDelayVisible:false,//申请延期
                dialogApplyVisible:false,//再次发起
                formLabelWidth: '120px',
                add_form:{
                    partNumber:"",
                    brand:'',
                    createDate:[],
                    validityDateStart:'',
                    validityDateEnd:'',
                    remark:'',
                },
                batch_form:{
                    createDate:[],
                    validityDateStart:'',
                    validityDateEnd:'',
                },
                applyform:{
                    createDate:[],
                    remark:'',
                },
                rules: {
                    partNumber: [
                        { required: true, message: '请输入优势型号', trigger: 'blur' },
                    ],
                    createDate:[
                        { required: true, message: '请选择有效期', trigger: 'blur' },
                    ]
                },
                batchrules:{
                    createDate:[
                        { required: true, message: '请选择有效期', trigger: 'blur' },
                    ]
                },
                applyRules:{
                    createDate:[
                        { required: true, message: '请选择有效期', trigger: 'change' },
                    ]
                },
                upload_file_url:'',
                upHeaders:{
                    // 'Authorization':"10cbce37a0a14f9a9d2305baac613b51",
                    // 'Token':'Bearer '+ getToken()
                },
                pickerOptions: {
                    shortcuts: [
                        {
                            text: '最近一周',
                            onClick(picker) {
                                const end = new Date();
                                const start = new Date();
                                start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
                                picker.$emit('pick', [start, end]);
                            },
                        },
                        {
                            text: '最近一个月',
                            onClick(picker) {
                                const end = new Date();
                                const start = new Date();
                                start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
                                picker.$emit('pick', [start, end]);
                            },
                        },
                        {
                            text: '最近三个月',
                            onClick(picker) {
                                const end = new Date();
                                const start = new Date();
                                start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
                                picker.$emit('pick', [start, end]);
                            },
                        },
                        {
                            text: '最近一年',
                            onClick(picker) {
                                const end = new Date();
                                const start = new Date();
                                start.setTime(start.getTime() - 3600 * 1000 * 24 * 365);
                                picker.$emit('pick', [start, end]);
                            },
                        },
                    ],
                },
                delayform:{
                    fileUrls:[],
                    validity:'',
                    remark:'',
                },
                brandList:[],
                brandId:[],
                isShow:false,
                isDisabled:false,
                allParams:{
                    advantageStatus: '',
                    auditStatus: '',
                    brand: "",
                    createUser: "",
                    idList: [],
                    isAll: false,
                    partNumber:'',
                    validityDateStart:'',
                    validityDateEnd:"",
                    remark:'',
                },
                // applyParams:{
                //     advantageStatus: '',
                //     auditStatus: '',
                //     brand: "",
                //     createUser: "",
                //     idList: [],
                //     isAll: false,
                //     partNumber:'',
                //     validityDateStart:'',
                //     validityDateEnd:"",
                //     remark:'',
                // },
                modelList:[],
                dialogresultVisible:false,
                gridData: [],
                result:{
                    brand:''
                },
                uploadfile:'',
               

            }
        },
        methods:{
            handleSelectChange(section) {
                // this.tableconfig.loading = section.length > 0 ? false : true;
                this.selectrow = section;
                console.log(this.selectrow,'333333');
                if(this.selectrow.length >= 1){
                   this.isbtndisabled = false;
                }else{
                    this.isbtndisabled = true;
                }
            },
            // 重置搜索
            doReset() {
                console.log(Object.keys(this.form).slice(0,-2),'this.ruleForm');
                Object.keys(this.form).slice(0,-2).map(x => {
                    this.form[x] = '';
                });
                console.log(this.form,'this.ruleForm.pageSize');
                this.$message({
                    message: '已重置',
                    type: 'success',
                });
                this.doRefresh();
            },
            // 刷新
            doRefresh() {
                //页码从第一页开始
                this.tableconfig.currentpage = 1;
                this.form.pageNo = 1;
                //表格回到顶部
                this.$refs.mytable.$emit('handleGoTop');
                this.doQuery();
            },
            //搜索
            async doQuery() {
                // 获取表格
                this.tableconfig.loading = true;
                this.tableconfig.currentpage = this.form.pageNo;
                this.tableconfig.pagesize = this.form.pageSize;
                let data1 = await modelList(this.form);
                console.log(data1);
                if(data1.success){
                    this.tableconfig.total = data1.result.total;
                    this.tableconfig.tabledata = data1.result.data;
                }
                this.tableconfig.loading = false;
            },
            // 页码数更新
            handleSizeChange(val) {
                this.form.pageNo = 1;
                this.form.pageSize = val;
                this.doQuery();
                //表格回到顶部
                this.$refs.mytable.$emit('handleGoTop');
            },
            // 当前页码更新
            handleCurrentChange(val) {
                this.form.pageNo = val;
                console.log(this.form.pageNo,'this.tableconfig.currentpage');
                this.doQuery();
                //表格回到顶部
                this.$refs.mytable.$emit('handleGoTop');
            },
            getAdd(){
                this.dialogAddVisible = true;
            },
            onInputBlur(e){
                if(e.target.value != ''){
                    this.queryBrands(e.target.value)
                }else{
                   this.add_form.brand = ''; 
                }
            },
            onInputChange(e){
                // this.queryBrands(e)
                // console.log(e,'eeeeeeeeeeeeeeeeee');
            },
            // 输入型号
            queryBrands(data){
                let params = {
                    partNumber: data
                }
                queryBrandsByPartNumber(params).then(res=>{
                    this.brandList = res.result;
                    if(this.brandList.length == 0){
                        this.isShow = true;
                        return false
                    }else if(this.brandList.length ==1){
                        this.isShow = false;
                        this.add_form.brand = this.brandList[0];
                        this.isDisabled = true;
                    }else{
                        this.isShow = false;
                        this.add_form.brand = '';
                        this.isDisabled = false;
                    }
                })
            
            },
            // 新增提交
            getaddSubmit(formName){
                console.log(this.add_form,'this.add_formthis.add_form');
                this.$refs[formName].validate((valid) => {
                    if (valid) {
                       this.add_form.validityDateStart =this.add_form.createDate[0];
                       this.add_form.validityDateEnd = this.add_form.createDate[1];
                        if(this.add_form.brand == ''){
                            let params = {
                                partNumber: this.add_form.partNumber
                            }
                            queryBrandsByPartNumber(params).then(res=>{
                                this.brandList = res.result;
                                if(this.brandList.length == 0){
                                    return false;
                                }else{
                                    this.$message.error('请选择品牌');
                                }
                            })
                            
                        }else{
                            console.log(this.add_form,'this.add_form11111111111');
                            checkAdvantageModel(this.add_form).then(res=>{
                                if(res.success){
                                    if(res.result){
                                        this.$message.error("该优势型号已存在");
                                        return false
                                    }else{
                                        addModel(this.add_form).then(res=>{
                                            console.log(res,'xinzeng');
                                            if(res.success){
                                                this.dialogAddVisible = false;
                                                this.doQuery();
                                                this.$refs['addform'].resetFields();
                                            }
                                        })
                                    }
                                
                                }
                             })
                        } 
                    } else {
                        return false;
                    }
                });
            },
            closeAdd(){
                this.$refs['addform'].resetFields();
                this.isDisabled = false;
                this.brandList = [];
            },
            clearUpload(data){
                this.uploadfile = data;
                this.modelList = [];
                
            },
            closeBatchAdd(){
                this.uploadfile.clearFiles();
                this.modelList=[];
                this.$refs['batch_form'].resetFields();
            },
            checkedAllVal(val){
                console.log(val,'checkedAllVal');
                this.allParams.isAll = val;
            },
            // 取消
            getConcel(){
                if(this.selectrow.length > 0){
                    let arr = [];
                    let arrbox = [];
                    this.selectrow.map(val=>{
                        console.log(val,'3333333333333333');
                        if(val.advantageStatus == 0 || val.advantageStatus == 1 && val.ifAdvantageBrand == 1 && val.inventoryCount != 0){
                            arr.push(val.id) 
                        }else{
                            arrbox.push(val.id) 
                        }
                    })
                    if(arr.length > 0 ){
                        this.$message.warning('优势型号包含无法操作选项');
                        return false;
                    }else{
                        this.brandId = arrbox;
                        console.log(this.brandId,'this.brandId');
                        this.dialogCancelVisible = true;
                    }
                }
            },
            getaCancelSubmit(){
                this.allParams.advantageStatus = this.form.advantageStatus;
                this.allParams.auditStatus = this.form.auditStatus;
                this.allParams.createUser = this.form.createUser;
                this.allParams.brand = this.form.brand;
                this.allParams.idList = this.brandId;
                this.allParams.partNumber = this.form.partNumber;
                console.log(this.allParams,'eeeeeeeeeeeeeeeee');
                cancleAdvantageModel(this.allParams).then(res=>{
                    // console.log(res,'取消');
                    if(res.success){
                        this.$message.success('选中的优势型号已无效');
                        this.dialogCancelVisible = false;
                        this.allParams.advantageStatus = '';
                        this.allParams.auditStatus = '';
                        this.allParams.createUser = '';
                        this.allParams.brand = '';
                        this.allParams.partNumber = '';
                        this.allParams.idList = [];
                        this.allParams.isAll = false
                        this.doQuery();
                    }else{
                        this.$message.error(res.message);
                    }
                })
            },
            //批量新增
            getDelay(){
                this.dialogDelayVisible = true;
            }, 
            // 再次发起
            getApply(){
                if(this.selectrow.length >= 1){
                    let arr = [];
                    let arrbox = [];
                    this.selectrow.map(val=>{
                        if(val.advantageStatus == 0 && val.auditStatus == 1 || val.advantageStatus == 0 &&val.auditStatus == 2){
                            arr.push(val.id) 
                        }else{
                            arrbox.push(val.id) 
                        }
                    })
                    if(arrbox.length > 0){
                        this.$message.warning('优势型号包含无法操作选项');
                        return false;
                    }else{
                        this.brandId = arr;
                        console.log(this.brandId,'this.brandId');
                        this.dialogApplyVisible = true;
                    }
                }else{
                    this.$message.warning('请选中至少一行的优势型号进行操作')
                }
            },
            getApplySubmit(formName){
                this.$refs[formName].validate((valid) => {
                    if (valid) {
                        this.allParams.advantageStatus = this.form.advantageStatus;
                        this.allParams.auditStatus = this.form.auditStatus;
                        this.allParams.createUser = this.form.createUser;
                        this.allParams.brand = this.form.brand;
                        this.allParams.partNumber = this.form.partNumber;
                        this.allParams.idList = this.brandId;
                        this.allParams.validityDateStart = this.applyform.createDate[0];
                        this.allParams.validityDateEnd = this.applyform.createDate[1];
                        this.allParams.remark = this.applyform.remark;
                        console.log(this.allParams,'this.allParamsapplyParamsapplyParamsapplyParams');
                        againInitiate( thisallParams).then(res=>{
                            if(res.success){
                                this.$message.success('优势品牌再起发起');
                                this.dialogApplyVisible = false;
                                this.allParams.advantageStatus = '';
                                this.allParams.auditStatus = '';
                                this.allParams.createUser = '';
                                this.allParams.brand = '';
                                this.allParams.idList = [];
                                this.allParams.partNumber = '';
                                this.allParams.isAll = false;
                                this.allParams.validityDateStart = '';
                                this.allParams.validityDateEnd = '';
                                this.allParams.remark = '';
                                this.doQuery();
                            }
                        })
                    }else{
                        return false; 
                    }
                })
              
                
            },
            closeApply(){
                this.$refs.applyform.resetFields();
            },
            //删除
            getDel(){
                if(this.selectrow.length >= 1){
                    let arr = [];
                    let arrbox = [];
                    this.selectrow.map(val=>{
                        if(val.ifAdvantageBrand == 1 && val.inventoryCount != 0){
                            arr.push(val.id);
                        }else{
                            arrbox.push(val.id) 
                        }
                    })
                    if(arr.length > 0 ){
                        this.$message.warning('优势型号包含无法操作选项');
                        return false;
                    }else{
                        this.dialogDelVisible = true;
                        this.brandId = arrbox;
                        console.log(this.brandId);
                    }
                }else{
                    this.$message.warning('请选中至少一行的优势型号进行操作')
                }
            },
            getDelSubmit(){
                this.allParams.advantageStatus = this.form.advantageStatus;
                this.allParams.auditStatus = this.form.auditStatus;
                this.allParams.createUser = this.form.createUser;
                this.allParams.brand = this.form.brand;
                this.allParams.partNumber = this.form.partNumber;
                this.allParams.idList = this.brandId;
                deleteModel(this.allParams).then(res=>{
                    if(res.success){
                        this.$message.success('优势型号已删除');
                        this.dialogDelVisible = false;
                        this.allParams.advantageStatus = '';
                        this.allParams.auditStatus = '';
                        this.allParams.createUser = '';
                        this.allParams.brand = '';
                        this.allParams.idList = [];
                        this.allParams.partNumber = '';
                        this.allParams.isAll = false;
                        this.doQuery();
                    }
                })
            },
            batchData(data){
                this.modelList = data;
            },
            getbatchSubmit(formName){
                console.log(this.batch_form,'this.batch_formthis.batch_form');
                this.$refs[formName].validate((valid) => {
                    if (valid) {
                       this.batch_form.validityDateStart =this.batch_form.createDate[0];
                       this.batch_form.validityDateEnd = this.batch_form.createDate[1];
                       if(this.modelList.length != 0){
                        let params = {
                            list:this.modelList,
                            validityDateStart:this.batch_form.validityDateStart,
                            validityDateEnd:this.batch_form.validityDateEnd
                        }
                        console.log(params,'paramsparamsparams');
                        batchAdd(params).then(res=>{
                            if(res.success){
                                if(res.result.approvedDataCount !=0 || res.result.inventoryNoHaveDataCount !=0 || res.result.reviewedDataCount !=0 ){
                                    this.dialogresultVisible = true;
                                    this.gridData = res.result;
                                }else{
                                    this.$message.success(res.message);
                                    this.uploadfile.clearFiles();
                                    this.dialogDelayVisible = false;
                                    this.doQuery();
                                    this.modelList = [];
                                }
                            }else{
                                this.$message.error(res.message);
                            }
                        })

                    }else{
                        this.$message.warning("请上传文件")
                    }
                    }
                })
              
                
            },
            gettableSumbit(){
                this.dialogresultVisible = false;
                this.dialogDelayVisible = false;
                this.doQuery();            
            }
        },
        created(){
            this.doQuery();
        },
        watch:{
            add_form:{
                handler(val,old){
                   if(val.partNumber == ''){
                    this.isShow = false;
                   }
                
                },
                deep:true,
                immediate:true,
            }
        }
    }
</script>

<style scoped lang="scss">
.brand{
    width: 100%;
    padding:20px 30px;
    .brand-head{
        width: 100%;
        padding: 20px 20px 10px;
        background: #fff;
        border-radius: 8px;
        align-items: center;
        .search{
            padding-top: 10px;
            .el-col-4.btn-box{
                text-align: right;
            }
        }
        .search-btn{
            width: 12%;
            display: flex;
            justify-content: flex-end;
            align-items: center;
            .btn{
                margin-bottom: 23px;
            }

        }

    }
    .operation-box{
        display: flex;
        padding: 20px;
    }
    .table-box{
        width: 100%;
        background: #fff;
        border-radius: 8px;
        padding: 0 20px;
        cursor: pointer;
        .look{
            margin-right: 20px;
        }
    }
    ::v-deep .el-table--enable-row-hover .el-table__body tr:hover > td{
        background-color: #E6F7FF !important;
    }
    .addform{
        width: 80%;
        margin: auto;
    }
    .dialog-footer{
        text-align: center;
    }
    .del-box{
        display: flex;
        flex-direction: column;
        align-items: center;
    }
    .del-icon{
        font-size: 50px;
        color: #008FFF;
    }
    .concel-icon{
        width: 60px;
        height: 60px;
        display: block;
    }
    .del-content{
        font-size: 24px;
        font-weight: 600;
        color: #333333;
        line-height: 22px;
    }
   ::v-deep .el-textarea__inner{
        min-height: 100px !important;
    }
    .look-box{
        width: 100%;
        display: flex;
        justify-content: space-between;
        .file-list{
            width: 30%;
            li{
                display: flex;
                justify-content: space-between;
                font-size: 14px;
                font-weight: 400;
                color: #333333;
                line-height: 20px;
                .file-look{
                    color: #008FFF;
                    min-width: 30px;
                }
            }
            
        }
        .file-pic{
            width: 65%;
        }
    }
    .upload-title{
        font-size: 14px;
        font-weight: 400;
        color: #000000;
        line-height: 22px;
        margin-bottom: 20px;
    }
    .cancel-dialog{
       ::v-deep .el-dialog:not(.is-fullscreen){
        margin-top: 28vh !important;
            .el-dialog__header{
                display: none;
            }
        }
    }
    .add-dialog{
        ::v-deep .el-dialog:not(.is-fullscreen){
            margin-top: 22vh !important;
        }
    }
}

.apply-dialog{
    ::v-deep .el-dialog:not(.is-fullscreen){
        margin-top: 28vh !important;
    }
}
.result-num{
    text-align: center;
    font-size: 14px;
    font-weight: 400;
    color: #333333;
    line-height: 20px;
    span{
        color: #E02020;
    }
}
.upload-box{
    // margin: 0 0 0 5%;
    margin-bottom: 20px;
}
.result-box{
    padding: 0 50px 0;
}
.tips{
    font-size: 14px;
    font-weight: 400;
    color: #E02020;
    line-height: 20px;
    text-align: center;
}
</style>